import heapq

nums = [1, 8, 2, 23, 7, -41, 18, 230, 42, 37, 2]
print(heapq.nlargest(1,nums))
print(heapq.nsmallest(1,nums))

print("-------------------------------------")

portfollo = [
    {"name":"IBM1","shares":1000,"price":130.12},
    {"name":"IBM2","shares":1010,"price":130.12},
    {"name":"IBM3","shares":1020,"price":320.12},
    {"name":"IBM4","shares":1030,"price":310.12},
    {"name":"IBM5","shares":1040,"price":320.12},
    {"name":"IBM6","shares":1050,"price":320.123},
]

cheap = heapq.nsmallest(3,portfollo,key=lambda s:s["price"])
expensive = heapq.nlargest(3,portfollo,key=lambda s:s["price"])

## 遍历字典
for k in cheap:
    print(k)